﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using YiYiTong.Rocket.Helper;

namespace YiYiTong.Rocket.ManageWeb
{
    public class ErrorAttribute : AuthorizeFilterAttribute, IExceptionFilter
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
        }

        /// <summary> 
        /// 异常 
        /// </summary> 
        /// <param name="filterContext"></param> 
        public void OnException(ExceptionContext filterContext)
        {
            //获取异常信息
            Exception Error = filterContext.Exception;
            //错误信息 
            string Message = Error.Message;
            //错误发生地址 
            string Url = HttpContext.Current.Request.RawUrl;
            filterContext.ExceptionHandled = true;

            //记录错误日志
            LogHelper.Error("异常拦截筛选器" + Error.Source + "\t" + Url + "\t" + Message + "\t" + Error.StackTrace);

            //跳转至错误提示页面
            filterContext.Result = new RedirectResult("/Home/Error/");
        }

    }

    /// <summary>
    /// 表示当前Action请求为一个具体的功能页面
    /// </summary>
    [AttributeUsage(AttributeTargets.Method)]
    public class ViewPageAttribute : Attribute { }

    /// <summary>
    /// 表示当前Action请求可以忽略权限判断
    /// </summary>
    [AttributeUsage(AttributeTargets.Method)]
    public class NoVerifyAttribute : Attribute { }
}